﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using V2TEK.NET.SH.Silverlight.Charts.Core;
using System.Collections.ObjectModel;
using V2TEK.NET.SH.Silverlight.Charts.GanttHelper;
using System.Collections.Specialized;

namespace V2TEK.NET.SH.Silverlight.Charts.TreeGridHelper
{
    /// <summary>
    /// 未完全实现，不可用
    /// </summary>
    public abstract class AbstractTreeGridLayout : AbstractEntryLayout<TaskEntryLayoutItem,RowItemsCollection>
    {
        public AbstractTreeGridLayout():base()
        {
            //this.BatchRowsChanged += new EventHandler(AbstractTreeGridLayout_BatchRowsChanged);
            this.Rows.CollectionChanged += new NotifyCollectionChangedEventHandler(Rows_CollectionChanged);
        }

        internal void Rows_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            switch (e.Action)
            {
                case NotifyCollectionChangedAction.Add:
                    foreach (RowItemsCollection row in e.NewItems)
                    {
                        if (row.Count > 0)
                            this.Items.Insert(e.NewStartingIndex, row[0]);
                    }
                    break;
                case NotifyCollectionChangedAction.Remove:
                    this.Items.Remove((e.OldItems[0] as RowItemsCollection)[0]);
                    break;
                case NotifyCollectionChangedAction.Reset:
                    this.Items.Clear();
                    break;
            }
            //throw new NotImplementedException();
        }

        #region IEntryLayout Members

        //protected virtual void CalculateItems()
        //{
        //    //so suprise, the treegrid will listen to the items change, if just clear ,it will single to single remove row
        //    //then single to single add row.

        //    //if (this.Items != null)
        //    //    this.Items.Clear();
        //    //else
        //    //    this.Items = new ObservableCollection<TaskEntryLayoutItem>();

        //    //int i = 0;
        //    //foreach (RowItemsCollection row in this.Rows)
        //    //{
        //    //    TaskEntryLayoutItem item = row[0];
        //    //    item.RowIndex = i;
        //    //    base.Items.Add(item);
        //    //    i++;
        //    //}
            
        //}

        public override void Update()
        {
            //CalculateItems();
            base.Update();
        }

        #endregion
    }
}
